﻿Imports System.Data.OleDb

Public Class VideosAdd
    Inherits System.Web.UI.Page


    Protected Sub btnAddVideo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddVideo.Click
        If txtvideid.Text = "" And txtvideotitle.Text = "" Then
            MsgBox("Sorry, you have not added the correct video code or / and a title for the video")
        Else
            Dim sql As String = "INSERT INTO Videos (VideoLink,VideoTitle,VideoDescription,DateUploaded,TimeUploaded,UsernameID) VALUES (@f1,@f2,@f3,@f4,@f5,@f6)"
            Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
            conn.Open()
            Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
            cmd.Parameters.AddWithValue("@f1", txtvideid.Text)
            cmd.Parameters.AddWithValue("@f2", txtvideotitle.Text)
            cmd.Parameters.AddWithValue("@f3", txtvideodescription.Text)
            cmd.Parameters.AddWithValue("@f4", Now.Date.ToString("dd/MM/yyyy"))
            cmd.Parameters.AddWithValue("@f5", DateTime.Now.ToString("t"))
            cmd.Parameters.AddWithValue("@f6", Membership.GetUser(User.Identity.Name).ProviderUserKey)

            cmd.ExecuteNonQuery()
            conn.Close()
            cmd.Dispose()
            conn.Dispose()

            Response.Redirect("VideosAdd.aspx")

        End If

    End Sub

End Class